import http from "../util/httpRequest.js"

let userTest = {
	id: 1,
	username: "ogbA_44fnEu4aNnnieP0XPr_Is_0",
	name: "陈亚如-test",
	phone: "17058179046",
	address: "四川农业大学2区15舍309",
	sex: 1,
	avatar: "https://xxl-1302724632.cos.ap-shanghai.myqcloud.com/sysUserAvatar/1/QQ%E5%9B%BE%E7%89%8720210328225418.jpg",
	token: "mock-token",
}

// 微信授权登录
export function loginByWeixin(params) {
	params.method = "POST"
	params.path = "/auth/login/weixin?code=" + params.code
	params.testData = "token-xxx"
	http(params)
}

// 测试号登录
export function loginTestUser(params) {
	params.method = "POST"
	params.path = "/auth/loginTestUser?username=" + params.username + "&code=" + params.code
	params.testData = "token-xxxxx"
	http(params)
}

// 退出登录
export function logout(params) {
	params.method = "DELETE"
	params.path = "/user/logout"
	http(params)
}

export function getUserInfo(params) {
	params.path = "/user/info"
	params.testData = userTest
	http(params)
}

// 更新个人信息
export function updateUser(params) {
	params.method = "PUT"
	params.path = "/user/info"
	params.data = params.user
	params.testData = function() {
		userTest = params.user
		return true
	}()
	http(params)
}
